package com.atguigu.flink.chapter06;

import com.atguigu.flink.bean.WaterSensor;
import com.atguigu.flink.chapter05.function.WaterSensorMapFunction;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.java.tuple.Tuple;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.KeyedStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.KeyedProcessFunction;
import org.apache.flink.streaming.api.functions.ProcessFunction;
import org.apache.flink.streaming.api.functions.co.KeyedCoProcessFunction;

public class ProcessDemo {
    public static void main(String[] args) {
        Configuration conf = new Configuration();
        conf.setInteger("rest.port", 2000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
        env.setParallelism(1);
        KeyedStream<WaterSensor, String> s1 = env.socketTextStream("hadoop102", 9999)
                .map(new WaterSensorMapFunction())
                //.process(new ProcessFunction<Object, Object>() {
                //})
                .keyBy(WaterSensor::getId);
        //.process(new KeyedProcessFunction<Tuple, Object, Object>() {
                //});

        //s1.connect(s1).process(new KeyedCoProcessFunction<Object, WaterSensor, WaterSensor, Object>() {
        //})

        try {
            env.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
